/**
 * Created by dale on 2017/8/8.
 */
$(document).ready(function () {
    var form=$('#form');
    var $form=new xhForm(form);
    var $icuId=addressUri.getParam('icuId');
    $('[name="iCUId"]').val($icuId);//设置客户id

    $('[name="sSubjects[]"]').select2();
    $('[name="sGrades[]"]').select2();
    var $icucId=addressUri.getParam('icucId');
    if($icucId!=null){

        xhExtra.ajaxRequest('customer/getContactData',{'iCUCId':$icucId},null,function (data) {
            $form.fill(data);
            if(data['sSubjects'] != null){
                $('[name="sSubjects[]"]').val(data['sSubjects'].split(',')).trigger('change');
            }
            if(data['sGrades'] != null){
                $('[name="sGrades[]"]').val(data['sGrades'].split(',')).trigger('change');
            }
            form.initeValidate($('#bt_modal_confirm',parent.document));
        })
    }else {
        $('#bt_modal_confirm',parent.document).addClass('disabled');
        form.initeValidate($('#bt_modal_confirm',parent.document));
    }

    
    $('#bt_modal_confirm',parent.document).click(function () {
        //form.submit();
        $form.submit('customer/saveContact',{},function (data) {
            window.top.xhTop.getActiveFrame().frames['customer']['contact'].location.reload();
            $('[name="sChargeName"]',window.top.xhTop.getActiveFrame().frames['customer'].document).val(data['sName']);
            $('[name="sChargePhone"]',window.top.xhTop.getActiveFrame().frames['customer'].document).val(data['sPhoneNum']);
            window.top.xhTop.closeModal();
        })
        // $.ajax({
        //     url:baseUrl+'customer/saveContact',
        //     data:$('#form').serialize(),
        //     dataType:'json',
        //     type:'post',
        //     success:function (data) {
        //         window.top.xhTop.getActiveFrame().frames['customer']['contact'].location.reload();
        //         $('[name="sChargeName"]',window.top.xhTop.getActiveFrame().frames['customer'].document).val(data['sName']);
        //         $('[name="sChargePhone"]',window.top.xhTop.getActiveFrame().frames['customer'].document).val(data['sPhoneNum']);
        //         window.top.xhTop.closeModal();
        //     },
        //     error:function (data) {
        //         console.log(data);
        //         window.top.xhTop.getActiveFrame().frames['customer']['contact'].location.reload();
        //         window.top.xhTop.closeModal();
        //     }
        // })

    });

    modalBind.bindClick();
    
    
});